<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML>
<html class="no-js">
<head>
	<title>注册大岭山中学网盘账号</title>
    
    <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,300' rel='stylesheet' type='text/css'>
	
	<link rel="stylesheet" href="static/css/bootstrap.min.css">
	<link rel="stylesheet" href="static/css/animate.css">
	<link rel="stylesheet" href="static/css/style.css">
	<script src="static/js/modernizr-2.6.2.min.js"></script>
	
	<style type="text/css">
		label.error{color:#ef392b;}
	</style>
	
</head>
  
<body class="style-3">
<div class="container">
	<div class="row">
		<div class="col-md-4 col-md-push-8">
			<form id="sign" action="" class="fh5co-form animate-box" data-animate-effect="fadeInRight" onsubmit="return false;">
				<h2>注册大岭山中学网盘账号</h2>
				<div class="form-group" hidden="hidden">
					<div class="alert alert-success" role="alert">注册成功.</div>
				</div>
				<div class="form-group">
					<input type="text" class="form-control" id="email" name="email" placeholder="请设置安全邮箱" autocomplete="off" onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;">
				</div>
				<div class="form-group">
					<input type="text" class="form-control" id="username" name="username" placeholder="请设置用户名" autocomplete="off" onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;">
				</div>
				<div class="form-group">
					<input type="password" class="form-control" id="password" name="password" placeholder="请设置登录密码" autocomplete="off" onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;">
				</div>
				<div class="form-group">
					<input type="password" class="form-control" id="re_password" name="re_password" placeholder="请确认密码" autocomplete="off" onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;">
				</div>
				<div class="form-group">
					<p>已经注册大岭山中学网盘账号? <a href="login.jsp">立即登录</a></p>
				</div>
				<div class="form-group">
					<input type="submit" value="注册" class="btn btn-primary">
				</div>
			</form>
		</div>
	</div>
</div>

<script src="static/jquery/1.9.1/jquery.min.js"></script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/jquery.placeholder.min.js"></script>
<script src="static/js/jquery.waypoints.min.js"></script>
<script src="static/js/main.js"></script>
<script type="text/javascript" src="static/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="static/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="static/layer/2.4/layer.js"></script>

<script type="text/javascript">
$(function(){
	$.validator.addMethod("checkEmail",function(value,element){
		var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
		return this.optional(element) || (reg.test(value));
	},"请输入正确的邮箱");
	$.validator.addMethod("checkUsername",function(value,element){
		var reg = /^[\u4e00-\u9fa50-9A-Za-z]+$/;
		return this.optional(element) || (reg.test(value));
	},"用户名只能为中英文和数字，不包含特殊字符");
	$("#sign").validate({
		onfocusout:function(element){
			$(element).valid();
		},
		rules:{
			email:{
				required:true,
				checkEmail: true,
				remote : {
					url : "user/checkValid.action",
					type : "post",
					data : {
						str : function(){
							return $('#email').val();
						},
						type : "email"
					},
					dataFilter:function(data,type){
						var d = $.parseJSON(data);
						if(d.status == 0){
							return true;
						}else{
							return false;
						}
					}
				}
			},
			username:{
				required: true,
				checkUsername : true,
				remote: {
					url : "user/checkValid.action",
					type : "post",
					data : {
						str : function(){
							return $('#username').val();
						},
						type : "username"
					},
					dataType : "json",
					dataFilter:function(data,type){
						var d = $.parseJSON(data);
						if(d.status == 0){
							return true;
						}else{
							return false;
						}
					}
				},
				minlength: "4",
				maxlength: "20"
			},
			password:{
				required: true,
				maxlength: "16",
				minlength: "6"
			},
			re_password:{
				required:true,
				equalTo: "#password",
				maxlength: "16",
				minlength: "6"
			}
		},
		messages:{
			email : {
				remote : "邮箱已存在"
			},
			username : {
				remote : "用户名已存在"
			},
			re_password:{
				equalTo :"两次密码输入不一致",
			}
		},
		onkeyup:false,
		focusCleanup:false,
		success:"valid",
		submitHandler:function(){
			$.post("user/register.action",$('#sign').serialize(),function(data){
				if(data.status == 0){
					layer.msg(data.msg+",正在为您登录,请稍后...",{icon: 6,time:2000},function(){
						$.post("user/login.action",$('#sign').serialize(),function(data){
							if(data.status == 0){
								window.location.href="${pageContext.request.contextPath}/index.action";
							}
						});
					});
				} else{
					layer.msg(data.msg,{icon:5});
				}
			})
		}
	});
});
</script>
</body>
</html>
